import { UseSearch, UseTable } from '@/components';
import { getStr } from '@/components/function';
import InnovationStudioController from '@/services/InnovationStudio/InnovationStudioController';
import { PageContainer } from '@ant-design/pro-layout';
import { Button, Card, Input, message, Modal, Radio } from 'antd';

import React from 'react';
const {confirm}=Modal
class Review extends React.Component {
    constructor(props) {
        super(props);
        let userInfo = JSON.parse(sessionStorage.getItem("userInfo"))
        this.state = { 
            dataSource:[],
            datas:{},
            userInfo:userInfo,
            query:{}
         };
    }
    getAgreementList=(query)=>{
        let {userInfo} = this.state
        query.targs = userInfo.targs
        return InnovationStudioController.getAgreementList(query)
    }
    handleSearch=(query)=>{
        this.setState({query})
        this.freshen()
    }
    reset=()=>{
        this.setState({query:{}})
        this.freshen()
    }
    freshen=()=>{
        this.setState({refresh:!this.state.refresh})
    }
    toAgreement=(record)=>{
        this.setState({
            record,
            visible:true
        })
    }
    submit=()=>{
        let {datas,userInfo,record}=this.state
        
        if(!datas.result){
            message.error("请选择审批意见")
            return
        }
        let that = this
        datas.targs = userInfo.targs
        datas.studioCode = record.studioCode
        datas.name = userInfo.name
        datas.userName = userInfo.userName
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                InnovationStudioController.agreementStudio(datas).then(r=>{
                    if(r&&r.data===1){
                        message.success('提交成功')
                        that.setState({visible:false})
                        that.freshen()
                    }
                })
            }
        })
    }
    handleChange=(key,e)=>{
        let {datas} = this.state
        datas[key] =e.target.value
        this.setState({datas})
    }
    render() {
        const {dataSource,visible,query,refresh}=this.state
        const columns=[
            {title:'工作室名称',dataIndex:'studioName',align:'center'},
            {title:'创建人',dataIndex:'studioLeaderName',align:'center'},
            {title:'创建时间',dataIndex:'createdAt',align:'center'},
            {title:'描述',dataIndex:'description',render:text=>getStr(text)},
            {title:'状态',dataIndex:'studioStatus',align:'center'},
            {title:'级别',dataIndex:'level',align:'center'},
            {title:'操作',render:(text,record)=><span>
                {record.studioStatus.indexOf('待')!==-1&&<Button onClick={this.toAgreement.bind(this,record)} type={'primary'}>审批</Button>}
                <Button></Button>
            </span>},
        ]
        const searchItem=[
            {name:'工作室名称',keyName:'studioName',valueType:'text'},
            
        ]
        return (
            <PageContainer>
                <Card>
                    <UseSearch searchItem={searchItem} handleSearch={this.handleSearch} reset={this.reset} />
                </Card>
                <Card>
                    <UseTable columns={columns} getData={this.getAgreementList} rowKeys={"studioCode"} query={query} refresh={refresh}/>
                </Card>
                {visible&&<Modal
                visible={visible}
                title={'审批'}
                onCancel={()=>this.setState({visible:false})}
                onOk={this.submit}
                >
                    <div>
                        <strong>意见：</strong>
                        <Radio.Group onChange={this.handleChange.bind(this,'result')}>
                            <Radio value={"同意"} key={1}>同意</Radio>
                            <Radio value={"不同意"} key={2}>不同意</Radio>
                        </Radio.Group>
                    </div>
                    <div>
                        <strong style={{verticalAlign:"top"}}>备注：</strong>
                        <Input.TextArea placeholder="请输入" onChange={this.handleChange.bind(this,'remark')} style={{width:350}}></Input.TextArea>
                    </div>
                </Modal>}
            </PageContainer>
        );
    }
}

export default Review;